/**
 * 城市分类系数列表
 * @author linfeng
 * @since 2019/08/24 16:06
 */
let priceType = 1;

layui.define(['index', 'form', 'table'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;

    table.init('zmn-table', {
        defaultToolbar: [],
        page: false,
        limit: json.bizType == 1 ? 4 : 3,
    });

    var val = $('input:radio[name="auditResult"]:checked').val();
    $("#auditComment").val("");
    if (val == 2) {
        $("#beizhu").show();
    } else {
        $("#beizhu").hide();
    }

    // 自定义验证规则
    form.verify({
        range: function (value) {
            if (value == '' || value == '0' || value == '0.0' || value == '0.00') {
                return;
            }
            if (value < 0.6 || value > 3) {
                return "系数值不符合规定,系数值范围0.6~3.0";
            }
            var reg = new RegExp("^[0-9]+.?[0-9]{0,2}$");
            if (!reg.test(value)) {
                return "请输入正确的格式!#.##";
            }
        }
    });

    priceType = json.priceType;
    form.on('radio(priceType)', function (data) {
        let value = data.value;
        priceType = value;
        replaceParamVal('priceType', priceType);
    });

    //替换指定传入参数的值,paramName为参数,replaceWith为新值
    function replaceParamVal(paramName, replaceWith) {
        var oUrl = this.location.href.toString();
        if (oUrl.indexOf('priceType') != -1) {
            var re = eval('/(' + paramName + '=)([^&]*)/gi');
            var nUrl = oUrl.replace(re, paramName + '=' + replaceWith);
            this.location = nUrl;
        } else {
            this.location = oUrl + "&priceType=" + priceType;
        }
    }

    $("input").blur(function () {
        $("#zmn-form-submit").click();
    });

    //对外暴露的接口
    exports('channel_price_list', {});
});

function selectPriceTable(channelId, bizType, tariffType) {
    zmnLayUtil.openIframeCustom(layer, "/channel/price/faultprice/select.action?channelId=" + json.channelId + "&bizType=" + bizType + "&tariffType=" + tariffType, {
        title: "选择价格表",
        area: ['60%', '50%'],
        id: 123
    })
}

function copyChannelRatio(channelId) {
    zmnLayUtil.openIframeCustom(layer, "/channel/toCopyChannelRatio.action?channelId=" + channelId + "&bizType=" + json.bizType + "&priceType=" + priceType, {
        title: "复制其他渠道系数",
        area: ['600px', '650px'],
        fixed: true,
        resize: false,
        id: 123
    })
}

/**
 * 描述: 设置折扣系数
 **/
function toSetDiscount(channelId, bizType) {
    zmnLayUtil.openIframeCustom(layer, "/channel/channelDiscount.action?channelId=" + channelId + "&priceType=" + priceType + "&bizType=" + bizType, {
        title: "折扣系数设置",
        shade: 0.9,
        area: ['580px', '530px']
    });
}
